//
//  ViewController.m
//  testcamera
//
//  Created by arthur on 2021/9/27.
//

#import "ViewController.h"
#import <TuyaSmartBaseKit/TuyaSmartBaseKit.h>
#import "TuyaViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UIButton *openBtn;
@property (strong,nonatomic) UIButton *loginBtn;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.openBtn];
    [self.view addSubview:self.loginBtn];
}

-(void)addDevice{
    TuyaViewController *tuyaVC = [[TuyaViewController alloc]init];
    tuyaVC.modalPresentationStyle = 0;
    [self presentViewController:tuyaVC animated:NO completion:nil];
}

-(void)loginAction{
    [[TuyaSmartUser sharedInstance] loginOrRegisterWithCountryCode:@"86" uid:@"463976" password:@"123456" createHome:YES success:^(id result) {
        NSLog(@"涂鸦登录成功");
        
        
                                        } failure:^(NSError *error) {
                                            NSLog(@"涂鸦登录失败");
                                           
                                        }];
}
-(UIButton *)loginBtn{
    if (_loginBtn == nil) {
        _loginBtn= [[UIButton alloc] initWithFrame:CGRectMake(30, 114, 50, 30)];
    }
    [_loginBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    _loginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_loginBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
    return _loginBtn;
}
-(UIButton *)openBtn{
    if (_openBtn == nil) {
        _openBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-80, 114, 50, 30)];
    }
    [_openBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_openBtn setTitle:@"打开" forState:UIControlStateNormal];
    _openBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_openBtn addTarget:self action:@selector(addDevice) forControlEvents:UIControlEventTouchUpInside];
    return _openBtn;
}

@end
